<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<?php
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$this->pageTitle=Yii::app()->name . ' - Member';
$this->breadcrumbs=array(
	'Member'
);

?>
<p>This is Member link</p>

<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'member-form',
	'enableClientValidation'=>true,
	//'clientOptions'=>array(
       //     'validateOnSubmit'=>true,
	//),
        'htmlOptions'=>array(
                               'onsubmit'=>"return false;",/* Disable normal form submit */
                               'onkeypress'=>" if(event.keyCode == 13){ send(); } " /* Do ajax call when user presses enter key */
                             ),
)); ?>
    <?php echo $form->errorSummary($model); ?>
    <div class="abc"></div>
   
        <div class="row">
		<?php echo $form->labelEx($model,'ID'); ?>
		<?php echo $form->textField($model,'id'); ?>
                <?php echo $form->error($model,'id'); ?>
		
	</div>  
        <div class="row">
		<?php echo $form->labelEx($model,'User'); ?>
		<?php echo $form->textField($model,'name'); ?>
                 <?php echo $form->error($model,'name'); ?>
		
	</div> 
        <div class="row">
		<?php echo $form->labelEx($model,'Password'); ?>
		<?php echo $form->textField($model,'password'); ?>
                
		
	</div> 
   
        <div class="row buttons">
		<?php echo CHtml::submitButton('Save',array('onclick'=>'send();')); ?>
	</div>
    
    </div>
    <?php  $this->endWidget(); ?>
</div><!-- form -->

<div id="loading"><?php $html = '';
            $html .= '<table>';
             $html .= '<tr><td>Num</td><td>Name</td><td>Edit</td><td>Delete</td></tr>';
             $num = 1;
                foreach ($list as $value) {
                    $del =  $value['id'];
                    $html .= '<tr><td>'.$num.'</td><td>'.$value['username'].'</td>'
                            .'<td><a href="#" onclick="editmember('.$value['id'].');">Edit</a></td>'
                            .'<td><a href="'.Yii::app()->createAbsoluteUrl("site/memberdelete/$del").'" >Delete</a></td>'
                            .'</tr>';
                    $num ++;
                }
            $html .= '</table>'; 
            echo $html; ?></div>

<script type="text/javascript">
 
function send()
 {
 
   var data= $("#member-form").serialize();
 
 //alert('data = ' + data);
  $.ajax({
   type: 'POST',
    url: '<?php echo Yii::app()->createAbsoluteUrl("site/ajaxmember"); ?>',
   data:data,
     beforeSend:function()
        {

             $('#loading').html('<p><img src="<?php echo Yii::app()->baseUrl; ?>/images/ajax-loader.gif"></p>'); 
        },
      success:function(data){
                //$("#loading").css({"display":"none"});
                
                $('#loading').html(data); 
            },
   //error: function(data) { // if error occured
   //      alert("Error occured.please try again");
   //      alert(data);
   // },
 
  //dataType:'html'
  });
 
}
function deletemember(mid)
{//alert(id);
   $.ajax({
        type: 'get',
        url: '<?php echo Yii::app()->createAbsoluteUrl("site/ajaxdelete/2233"); ?>',
       // data: 'js:{"id":mid}',
         beforeSend:function()
            {
                 $('#loading').html('<p><img src="<?php echo Yii::app()->baseUrl; ?>/images/ajax-loader.gif"></p>'); 
            },
          success:function(data){
                    //$("#loading").css({"display":"none"});
                    $('#loading').html(data); 
                },
     });
}
 
</script>